// 注册全局提示框组件

import Vue from 'vue'
import MessageBox from './index.vue'

// 创建一个 使用基础 Vue 构造器，创建一个 子类
const Message = Vue.extend(MessageBox)

MessageBox.install = (options, type) => {
  if (options === undefined || options === null) {
    options = {
      content: '',
    }
  } else if (typeof options === 'string' || typeof options === 'number') {
    options = {
      content: options,
    }
    if (type !== undefined || type !== null) {
      options.type = type
    }
  }

  // 手动渲染
  let instance = new Message({
    data: options,
  }).$mount()
  // 挂载
  document.body.appendChild(instance.$el)
  // visible置为true 显示
  Vue.nextTick(() => {
    instance.visible = true
  })
}

export default MessageBox.install
